package com.aletto.general_store.ui.adapters;

import android.widget.ImageView;
import android.widget.RatingBar;

import com.aletto.general_store.R;

import com.aletto.general_store.data.model.OrderScore;
import com.aletto.general_store.utils.image.GlideApp;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

import androidx.annotation.NonNull;

public class GoodsCommentAdapter extends BaseQuickAdapter<OrderScore, BaseViewHolder> {

    public GoodsCommentAdapter() {
        super(R.layout.item_goods_comment);
    }

    public GoodsCommentAdapter(List<OrderScore> data) {
        super(R.layout.item_goods_comment, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, OrderScore item) {

//        if (item.getName() == null){
//            OrderScore.ShopDTO shop = item.getShop();
//            holder.setText(R.id.tv_name, shop.getName());
//        }

        holder.setText(R.id.tv_comment_score, item.getScore())
                .setText(R.id.tv_goods_title, item.getGoods_name());

        RatingBar rating_comment_score = holder.getView(R.id.rating_comment_score);
        rating_comment_score.setRating(Float.parseFloat(item.getScore())); // TODO:  / 2

        if (item.getHead_img() != null){ // 用户头像
            ImageView ivAvatar = holder.getView(R.id.iv_avatar);
            GlideApp.with(ivAvatar).load(item.getHead_img()).avatar().into(ivAvatar);
        }

        if (item.getName() != null){ // 用户昵称
            holder.setText(R.id.tv_name, item.getName());
        }
    }

}
